@extends('manage.layout')

@section('content')
    <section class="content-header">
        <h1>
            订单列表
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="#">Order</a></li>
            <li class="active">Order List</li>
        </ol>
        <div class="input-group margin">
            <form action="{{ url('order/list') }}" method="get">
                {{--{{ csrf_field() }}--}}
                <select style="width: 150px" id="sel"  name="type" class="form-control" onchange="select()">
                    @foreach($searchtype as $value)
                        <option value="{{ $value['id'] }}">{{ $value['searchtype'] }}</option>
                    @endforeach
                </select>

                <div style="float: left" id="form">
                    <input id="datepicker" style="width: 200px"  name="param" type="text" class="form-control">
                    {{--<input style="width: 200px" type="text" name="param" class="form-control" id="datepicker">--}}
                </div>
                <input  type="submit" class="btn btn-info btn-flat" value="Go!">
            </form>
            <script>
                function select() {
                    var val = $('#sel option:selected').val();
                    console.log(val);
                    if(val == 2) {
                        $('#datepicker').datepicker({
                            autoclose: true,
                            format: 'yyyy-mm-dd'
                        });
                    }
                    else{
                        $('#datepicker').datepicker('remove');
                    }
                }
            </script>
        </div>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-header">
                        <h3 class="box-title">内容</h3>
                        <span style="float:right;color: #bbb">共{{$count}}条结果</span>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body">
                        <table class="table table-bordered table-hover">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>创建时间</th>
                                <th>
                                    更新时间&nbsp;&nbsp;
                                    <a href="/order/list?type={{$search}}&param={{$param}}&orderBy=1"><i class="fa fa-arrow-up"></i></a>&nbsp;&nbsp;
                                    <a href="/order/list?type={{$search}}&param={{$param}}&orderBy=2"><i class="fa fa-arrow-down"></i></a>
                                </th>
                                <th>名称</th>
                                <th>订单编号</th>
                                <th>项目编号</th>
                                {{--<th>公司名称</th>--}}
                                {{--<th>开始时间</th>--}}
                                {{--<th>结束时间</th>--}}
                                <th>服务商</th>
                                <th>价格</th>
                                {{--<th>付款明细</th>--}}
                                {{--<th>附件</th>--}}
                                <th>状态</th>
                                <th>操作状态</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($order as $o)
                                <tr>
                                    <td>{{ $o['id'] }}</td>
                                    <td>{{ $o['create_time'] }}</td>
                                    <td>{{ $o['update_time'] }}</td>
                                    <td>{{ $o['name'] }}</td>
                                    <td>{{ $o['order_code'] }}</td>
                                    <td>{{ App\Model\Project::find($o['project_id'])['name'] }}</td>
                                    {{--<td>{{ $o['company'] }}</td>--}}
                                    {{--<td>{{ $o['start_time'] }}</td>--}}
                                    {{--<td>{{ $o['stop_time'] }}</td>--}}
                                    <td>{{ App\Model\ServiceProvider::find($o['provider'])['name'] }}</td>
                                    <td>{{ $o['price'] }}元</td>
                                    {{--<td>{{ $o['detail'] }}</td>--}}
                                    {{--<td>{{ $o['attachment'] }}</td>--}}
                                    <td>
                                        <a href="/order/list?searchtype=100&param={{$o['status']}}">
                                            @if($o['status'] == 0)<label>待审核</label>
                                            @else<label>已审核</label>
                                            @endif
                                        </a>
                                    </td>
                                    <td>
                                        <a class="btn btn-info btn-xs" href="/order/details/{{ $o['id'] }}">订单详情</a>
                                        <div class="btn-group">
                                            {{--<button type="button" class="btn btn-info btn-sm">@if($o['status'] === 0)待审核@elseif($o['status'] === 1)待付款@elseif($o['status'] === 2)付款中@elseif($o['status'] === 3)已付款@endif</button>--}}
                                            <button type="button" class="btn btn-warning btn-xs">@if($o['status'] === 0)待审核@elseif($o['status'] === 1)已审核@endif</button>
                                            <button id="button" type="button" class="btn btn-warning btn-xs dropdown-toggle" data-toggle="dropdown">
                                                <span class="caret"></span>
                                                <span class="sr-only">Toggle Dropdown</span>
                                            </button>
                                            <ul class="dropdown-menu" role="menu">
                                                <li><a href="javascript:orderStatus('{{ $o['id'] }}',0)">待审核</a></li>
                                                <li><a href="javascript:orderStatus('{{ $o['id'] }}',1)">已审核</a></li>
                                                {{--<li><a href="javascript:orderStatus('{{ $o['id'] }}',1)">待付款</a></li>--}}
                                                {{--<li><a href="javascript:orderStatus('{{ $o['id'] }}',2)">付款中</a></li>--}}
                                                {{--<li><a href="javascript:orderStatus('{{ $o['id'] }}',3)">已付款</a></li>--}}

                                            </ul>
                                        </div>
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                    </div>
                    <!-- /.box-body -->
                    <div style="text-align: center;">
                        {{ $order->appends(['type'=>$search,'param'=>$param,'orderBy'=>$orderBy,'count'=>$count])->links() }}
                    </div>
                </div>
            </div>
            <!-- /.col -->
        </div>
        <!-- /.row -->
    </section>
@stop
@section('script')
    <script>

        //状态修改
        function orderStatus(id,status) {
            console.log(id);
            console.log(status);
            $.ajax({
                url: '/order/orderStatus',
                type: "GET",
                data: {id:id,status:status},
                dataType: "json",
                success: function(res) {
                    console.log(res);
                    if(res.code == 101) {
//
                        layer.msg(res.msg, {time:1500, icon:5})
                    }
                    else {
                        layer.msg(res.msg, {time:1500, icon:6});
                        window.location.href=window.location.href;
                    }
                }
            });
        }
    </script>
@stop